home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Python 1.4 / Python 1.4 source / Mac / GUSI-mods / GUSI.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-17  |  9.0 KB  |  365 lines  |  [TEXT/CWIE]

  1. /*********************************************************************
  2. Project    :    GUSI                -    Grand Unified Socket Interface
  3. File        :    GUSI.h            -    Socket calls
  4. Author    :    Matthias Neeracher
  5. Language    :    MPW C/C++
  6.  
  7. $Log: GUSI.h,v $
  8. Revision 1.2  1994/12/31  01:45:54  neeri
  9. Fix alignment.
  10.  
  11. Revision 1.1  1994/02/25  02:56:49  neeri
  12. Initial revision
  13.  
  14. Revision 0.15  1993/06/27  00:00:00  neeri
  15. f?truncate
  16.  
  17. Revision 0.14  1993/06/20  00:00:00  neeri
  18. Changed sa_constr_ppc
  19.  
  20. Revision 0.13  1993/02/14  00:00:00  neeri
  21. AF_PAP
  22.  
  23. Revision 0.12  1992/12/08  00:00:00  neeri
  24. getcwd()
  25.  
  26. Revision 0.11  1992/11/15  00:00:00  neeri
  27. remove netdb.h definitions
  28.  
  29. Revision 0.10  1992/09/26  00:00:00  neeri
  30. Separate dirent and stat
  31.  
  32. Revision 0.9  1992/09/12  00:00:00  neeri
  33. Hostname stuff
  34.  
  35. Revision 0.8  1992/09/07  00:00:00  neeri
  36. readlink()
  37.  
  38. Revision 0.7  1992/08/03  00:00:00  neeri
  39. sa_constr_ppc
  40.  
  41. Revision 0.6  1992/07/21  00:00:00  neeri
  42. sockaddr_atlk_sym
  43.  
  44. Revision 0.5  1992/06/26  00:00:00  neeri
  45. choose()
  46.  
  47. Revision 0.4  1992/05/18  00:00:00  neeri
  48. PPC stuff
  49.  
  50. Revision 0.3  1992/04/27  00:00:00  neeri
  51. getsockopt()
  52.  
  53. Revision 0.2  1992/04/19  00:00:00  neeri
  54. C++ compatibility
  55.  
  56. Revision 0.1  1992/04/17  00:00:00  neeri
  57. bzero()
  58.  
  59. *********************************************************************/
  60.  
  61. #ifndef _GUSI_
  62. #define _GUSI_
  63.  
  64. #include <sys/types.h>
  65.  
  66. /* Feel free to increase FD_SETSIZE as needed */
  67. #define GUSI_MAX_FD    FD_SETSIZE
  68.  
  69. #include <sys/cdefs.h>
  70. #include <compat.h>
  71. #include <sys/ioctl.h>
  72. #include <sys/fcntl.h>
  73. #include <sys/stat.h>
  74. #include <dirent.h>
  75. #include <Types.h>
  76. #include <Events.h>
  77. #include <Files.h>
  78. #include <AppleTalk.h>
  79. #include <CTBUtilities.h>
  80. #include <Packages.h>
  81. #include <PPCToolBox.h>
  82. #include <stdio.h>
  83. #include <sys/time.h>
  84. #include <sys/socket.h>
  85. #include <string.h>
  86. #include <netinet/in.h>
  87. #include <netdb.h>
  88. #include <sys/un.h>
  89. #include <unistd.h>
  90. #include <machine/endian.h>
  91.  
  92. typedef enum spin_msg {
  93.     SP_MISC,                /* some weird thing, usually just return immediately if you get this */
  94.     SP_SELECT,            /* in a select call */
  95.     SP_NAME,                /* getting a host by name */
  96.     SP_ADDR,                /* getting a host by address */
  97.     SP_STREAM_READ,    /* Stream read call */
  98.     SP_STREAM_WRITE,    /* Stream write call */
  99.     SP_DGRAM_READ,        /* Datagram read call */
  100.     SP_DGRAM_WRITE,    /* Datagram write call */
  101.     SP_SLEEP,            /* sleeping, passes ticks left to sleep */
  102.     SP_AUTO_SPIN        /* Autospin, passes argument to SpinCursor */
  103. } spin_msg;
  104.  
  105. typedef int (*GUSISpinFn)(spin_msg msg, long param);
  106. typedef void (*GUSIEvtHandler)(EventRecord * ev);
  107. typedef GUSIEvtHandler    GUSIEvtTable[24];
  108.  
  109. /*
  110.  * Address families, defined in sys/socket.h
  111.  *
  112.  
  113. #define    AF_UNSPEC         0        // unspecified
  114. #define    AF_UNIX             1        // local to host (pipes, portals)
  115. #define    AF_INET             2        // internetwork: UDP, TCP, etc.
  116. #define    AF_CTB             3        // Apple Comm Toolbox (not yet supported)
  117. #define    AF_FILE             4        // Normal File I/O (used internally)
  118. #define    AF_PPC             5        // PPC Toolbox
  119. #define    AF_PAP             6        // Printer Access Protocol (client only)
  120. #define    AF_APPLETALK    16        // Apple Talk
  121.  
  122. */
  123.  
  124. #define    ATALK_SYMADDR 272        /* Symbolic Address for AppleTalk             */
  125.  
  126. /*
  127.  * Some Implementations of GUSI require you to call GUSISetup for the
  128.  * socket families you'd like to have defined. It's a good idea to call
  129.  * this for *all* implementations.
  130.  *
  131.  * GUSIDefaultSetup() will include all socket families.
  132.  *
  133.  * Never call any of the GUSIwithXXX routines directly.
  134.  */
  135.  
  136. __BEGIN_DECLS
  137. void GUSIwithAppleTalkSockets();
  138. void GUSIwithInternetSockets();
  139. void GUSIwithPAPSockets();
  140. void GUSIwithPPCSockets();
  141. void GUSIwithUnixSockets();
  142. void GUSIwithSIOUXSockets();
  143. void GUSIwithMPWSockets();
  144.  
  145. void GUSISetup(void (*socketfamily)());
  146. void GUSIDefaultSetup();
  147. void GUSILoadConfiguration(Handle);
  148. __END_DECLS
  149. /*
  150.  * Types,  defined in sys/socket.h
  151.  *
  152.  
  153. #define    SOCK_STREAM         1        // stream socket 
  154. #define    SOCK_DGRAM         2        // datagram socket
  155.  
  156. */
  157.  
  158. #if defined(powerc) || defined (__powerc)
  159. #pragma options align=mac68k
  160. #endif
  161.  
  162. /*
  163.  * Defined in sys/un.h
  164.  *
  165.  
  166. struct sockaddr_un {
  167.     short        sun_family;
  168.     char         sun_path[108];
  169. };
  170.  
  171. */
  172.  
  173. #ifndef PRAGMA_ALIGN_SUPPORTED
  174. #error Apple had some fun with the conditional macros again
  175. #endif
  176.  
  177. #if PRAGMA_ALIGN_SUPPORTED
  178. #pragma options align=mac68k
  179. #endif
  180.  
  181. struct sockaddr_atlk {
  182.     short            family;
  183.     AddrBlock    addr;
  184. };
  185.  
  186. struct sockaddr_atlk_sym {
  187.     short            family;
  188.     EntityName    name;
  189. };
  190.  
  191. struct sockaddr_ppc {
  192.     short                    family;
  193.     LocationNameRec    location;
  194.     PPCPortRec            port;
  195. };
  196.  
  197. /* Definitions for choose() */
  198.  
  199. #define     CHOOSE_DEFAULT    1        /*    Use *name as default name                        */
  200. #define    CHOOSE_NEW        2        /* Choose new entity name, not existing one    */
  201. #define    CHOOSE_DIR        4        /* Choose a directory name, not a file         */
  202.  
  203. typedef struct {
  204.     short            numTypes;
  205.     SFTypeList    types;
  206. } sa_constr_file;
  207.  
  208. typedef struct {
  209.     short            numTypes;
  210.     NLType        types;
  211. } sa_constr_atlk;
  212.  
  213. /* Definitions for sa_constr_ppc */
  214.  
  215. #define PPC_CON_NEWSTYLE        0x8000    /* Required */
  216. #define PPC_CON_MATCH_NAME        0x0001    /* Match name */
  217. #define PPC_CON_MATCH_TYPE     0x0002     /* Match port type */
  218. #define PPC_CON_MATCH_NBP        0x0004    /* Match NBP type */
  219.  
  220. typedef struct    {
  221.     short            flags;
  222.     Str32            nbpType;
  223.     PPCPortRec    match;
  224. } sa_constr_ppc;
  225.  
  226. #if PRAGMA_ALIGN_SUPPORTED
  227. #pragma options align=reset
  228. #endif
  229.  
  230. __BEGIN_DECLS
  231. /* 
  232.  * IO/Socket stuff, defined elsewhere (unistd.h, sys/socket.h
  233.  *
  234.  
  235. int socket(int domain, int type, short protocol);
  236. int bind(int s, void *name, int namelen);
  237. int connect(int s, void *addr, int addrlen);
  238. int listen(int s, int qlen);
  239. int accept(int s, void *addr, int *addrlen);
  240. int close(int s);
  241. int read(int s, char *buffer, unsigned buflen);
  242. int readv(int s, struct iovec *iov, int count);
  243. int recv(int s, void *buffer, int buflen, int flags);
  244. int recvfrom(int s, void *buffer, int buflen, int flags, void *from, int *fromlen);
  245. int recvmsg(int s,struct msghdr *msg,int flags);
  246. int write(int s, const char *buffer, unsigned buflen);
  247. int writev(int s, struct iovec *iov, int count);
  248. int send(int s, void *buffer, int buflen, int flags);
  249. int sendto (int s, void *buffer, int buflen, int flags, void *to, int tolen);
  250. int sendmsg(int s,struct msghdr *msg,int flags);
  251. int select(int width, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
  252. int getdtablesize(void);
  253. int getsockname(int s, void *name, int *namelen);
  254. int getpeername(int s, struct sockaddr *name, int *namelen);
  255. int shutdown(int s, int how);
  256. int fcntl(int s, unsigned int cmd, int arg);
  257. int dup(int s);
  258. int dup2(int s, int s1);
  259. int ioctl(int d, unsigned int request, long *argp);
  260. int getsockopt(int s, int level, int optname, char *optval, int * optlen);
  261. int setsockopt(int s, int level, int optname, char *optval, int optlen);
  262. int isatty(int);
  263. int remove(const char *filename);
  264. int rename(const char *oldname, const char *newname);
  265. int creat(const char*);
  266. int faccess(char*, unsigned int, long*);
  267. long lseek(int, long, int);
  268. int open(const char*, int);
  269. int unlink(char*);
  270. int symlink(char* linkto, char* linkname);
  271. int readlink(char* path, char* buf, int bufsiz);
  272. int truncate(char *path, long length);
  273. int ftruncate(int fd, long length);
  274. int chdir(char * path);
  275. int mkdir(char * path);
  276. int rmdir(char * path);
  277. char * getcwd(char * buf, int size);
  278. */
  279.  
  280. /* 
  281.  * Defined in stdio.h
  282.  */
  283.  
  284. #ifdef __MWERKS__
  285. void fsetfileinfo (char *filename, unsigned long newcreator, unsigned long newtype);
  286. #endif
  287.  
  288. void fgetfileinfo (char *filename, unsigned long * creator, unsigned long * type);
  289.  
  290. #ifdef __MWERKS__
  291. FILE *fdopen(int fd, const char *mode);
  292. int fwalk(int (*func)(FILE * stream));
  293. #endif
  294.  
  295. int choose(
  296.         int         domain,
  297.         int         type,
  298.         char *     prompt,
  299.         void *     constraint,
  300.         int         flags,
  301.         void *     name,
  302.         int *     namelen);
  303.  
  304. /* 
  305.  * Hostname routines, defined in netdb.h
  306.  *
  307.  
  308. struct hostent * gethostbyname(char *name);
  309. struct hostent * gethostbyaddr(struct in_addr *addrP, int, int);
  310. int gethostname(char *machname, long buflen);
  311. struct servent * getservbyname (char * name, char * proto);
  312. struct protoent * getprotobyname(char * name);
  313.  
  314. */
  315.  
  316. char * inet_ntoa(struct in_addr inaddr);
  317. struct in_addr inet_addr(char *address);
  318.  
  319. /* 
  320.  * GUSI supports a number of hooks. Every one of them has a different prototype, but needs
  321.  * to be passed as a GUSIHook
  322.  */
  323.  
  324. typedef enum {
  325.     GUSI_SpinHook,    /* A GUSISpinFn, to be called when a call blocks */
  326.     GUSI_ExecHook /* Boolean (*hook)(const GUSIFileRef & ref), decides if file is executable */
  327. } GUSIHookCode;
  328.  
  329. typedef void (*GUSIHook)(void);
  330. void GUSISetHook(GUSIHookCode code, GUSIHook hook);
  331. GUSIHook GUSIGetHook(GUSIHookCode code);
  332.  
  333. /* 
  334.  * What to do when a routine blocks
  335.  */
  336.  
  337. /* Defined for compatibility */
  338. #define GUSISetSpin(routine)    GUSISetHook(GUSI_SpinHook, (GUSIHook)routine)
  339. #define GUSIGetSpin()            (GUSISpinFn) GUSIGetHook(GUSI_SpinHook)
  340.  
  341. int GUSISetEvents(GUSIEvtTable table);
  342. GUSIEvtHandler * GUSIGetEvents(void);
  343.  
  344. extern GUSIEvtHandler    GUSISIOWEvents[];
  345.  
  346. #define SIGPIPE    13
  347. #define SIGALRM    14
  348.  
  349. /* 
  350.  * BSD memory routines, defined in compat.h
  351.  *
  352.  
  353. #define index(a, b)                        strchr(a, b)
  354. #define rindex(a, b)                        strrchr(a, b)
  355. #define bzero(from, len)                 memset(from, 0, len)
  356. #define bcopy(from, to, len)            memcpy(to, from, len)
  357. #define bcmp(s1, s2, len)                memcmp(s1, s2, len)
  358. #define bfill(from, len, x)            memset(from, x, len)
  359.  
  360.  */
  361.  
  362. __END_DECLS
  363.  
  364. #endif /* !_GUSI_ */
  365.